Add ESM support configuration for Jest and update Octokit plugin imports #415
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
This project was unable to use ESM (ECMAScript Modules) packages from the Octokit ecosystem due to Jest test failures. When attempting to install packages like
@octokit/[email protected]
or@octokit/plugin-paginate-graphql
, Jest would fail with:This prevented the project from adopting newer versions of Octokit dependencies that have migrated to ESM.
Solution
This PR adds ESM support configuration that allows the project to work with dual-mode ESM/CommonJS packages while maintaining full Jest compatibility.
Changes Made
1. Jest Configuration (
jest.config.js
)Created a new Jest configuration file with
transformIgnorePatterns
to enable Babel transformation of@octokit/*
packages:This tells Jest to transform ESM imports from Octokit packages to CommonJS during tests, while still ignoring other node_modules packages for performance.
2. Updated Import Statements
Fixed import statements to use the correct export name from
@octokit/plugin-retry
:This change was applied to:
src/main.js
src/functions/post.js
src/functions/admin.js
The
{retry}
import is the actual export name from the package and works with both v6 (current) and future ESM versions.3. Documentation (
docs/esm-support.md
)Added comprehensive documentation explaining:
@octokit/[email protected]
)What This Enables
✅ Dual-mode ESM packages - Packages that provide both CommonJS and ESM entry points now work seamlessly (e.g.,
@octokit/[email protected]
,@octokit/[email protected]
)✅ ESM-ready configuration - The project is prepared for future migration to full ESM
✅ No breaking changes - All existing functionality is preserved
Known Limitation
Pure ESM packages (with
"type": "module"
and only ESM exports) like@octokit/[email protected]+
are not yet supported. Supporting these would require converting the entire project to ESM, including updating all ~35 test files to import Jest globals from@jest/globals
. The documentation provides guidance on this future migration path.Testing
Security
transformIgnorePatterns
is scoped specifically to@octokit/*
packages to minimize transformation overheadCloses #XXX (the ESM support issue)
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
img.shields.io
node /home/REDACTED/work/branch-deploy/branch-deploy/node_modules/.bin/make-coverage-badge --output-path ./badges/coverage.svg
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>Help! - Full ESM Support 🆘</issue_title>
<issue_description># Full ESM Support
This issue is a call for help from any and all JavaScript wizards.
I have given it my best go (about ~4 times now) to allow for supporting ESM + Jest tests with this project. I have been unsuccessful and I think I'm in over my head with JavaScript so I could use a hand from someone who is deeply familiar with JS + ESM + Jest.
Why?
This project relies on a few Octokit packages:
There is a shift in the open source community to have JS projects be full ESM. Recently the octokit/plugin-retry.js moved to full ESM in v7.0.0. This is a breaking change and in order to adopt their latest versions, this project needs to have ESM modules not explode when running
npm test
with Jest.The issue
The issue could have multiple layers and I will struggle to even explain it due to my lack of understanding with JavaScript + ESM + Jest (I use Ruby for most projects here at GitHub and this one is an exception because... Actions).
The issue begins when you install a pure ESM package. Here is an example of a package that this Action would like to use in the future:
Now that the package is installed, try to run the test suite:
💥
I have tried many variants of the followin...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.